﻿using System;
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Data;
using RBS.DBUtility;
using RBS.Common;
namespace RBS.Core.DAL
{
    //V_OrderDept
    public partial class V_OrderDept
    {

        public bool Exists(int Id, int OrderId, int HCId, string cName, int Num, decimal Price, int State, DateTime OperateDate, string CategoryName, int HotelId, string RoleName, int roleid, int DineTable, string Dinecondition, string DineTableName)
        {
            var strSql = new StringBuilder();
            strSql.Append("select count(1) from V_OrderDept");
            strSql.Append(" where ");
            strSql.Append(" Id = @Id and  ");
            strSql.Append(" OrderId = @OrderId and  ");
            strSql.Append(" HCId = @HCId and  ");
            strSql.Append(" cName = @cName and  ");
            strSql.Append(" Num = @Num and  ");
            strSql.Append(" Price = @Price and  ");
            strSql.Append(" State = @State and  ");
            strSql.Append(" OperateDate = @OperateDate and  ");
            strSql.Append(" CategoryName = @CategoryName and  ");
            strSql.Append(" HotelId = @HotelId and  ");
            strSql.Append(" RoleName = @RoleName and  ");
            strSql.Append(" roleid = @roleid and  ");
            strSql.Append(" DineTable = @DineTable and  ");
            strSql.Append(" Dinecondition = @Dinecondition and  ");
            strSql.Append(" DineTableName = @DineTableName  ");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4),
					new SqlParameter("@OrderId", SqlDbType.Int,4),
					new SqlParameter("@HCId", SqlDbType.Int,4),
					new SqlParameter("@cName", SqlDbType.NVarChar,50),
					new SqlParameter("@Num", SqlDbType.Int,4),
					new SqlParameter("@Price", SqlDbType.Decimal,5),
					new SqlParameter("@State", SqlDbType.Int,4),
					new SqlParameter("@OperateDate", SqlDbType.DateTime),
					new SqlParameter("@CategoryName", SqlDbType.NVarChar,50),
					new SqlParameter("@HotelId", SqlDbType.Int,4),
					new SqlParameter("@RoleName", SqlDbType.NVarChar,50),
					new SqlParameter("@roleid", SqlDbType.Int,4),
					new SqlParameter("@DineTable", SqlDbType.Int,4),
					new SqlParameter("@Dinecondition", SqlDbType.NVarChar,50),
					new SqlParameter("@DineTableName", SqlDbType.NVarChar,50)			};
            parameters[0].Value = Id;
            parameters[1].Value = OrderId;
            parameters[2].Value = HCId;
            parameters[3].Value = cName;
            parameters[4].Value = Num;
            parameters[5].Value = Price;
            parameters[6].Value = State;
            parameters[7].Value = OperateDate;
            parameters[8].Value = CategoryName;
            parameters[9].Value = HotelId;
            parameters[10].Value = RoleName;
            parameters[11].Value = roleid;
            parameters[12].Value = DineTable;
            parameters[13].Value = Dinecondition;
            parameters[14].Value = DineTableName;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }



        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(RBS.Core.Model.V_OrderDept model)
        {
            var strSql = new StringBuilder();
            strSql.Append("insert into V_OrderDept(");
            strSql.Append("Id,HotelId,RoleName,roleid,DineTable,Dinecondition,DineTableName,OrderId,HCId,cName,Num,Price,State,OperateDate,CategoryName");
            strSql.Append(") values (");
            strSql.Append("@Id,@HotelId,@RoleName,@roleid,@DineTable,@Dinecondition,@DineTableName,@OrderId,@HCId,@cName,@Num,@Price,@State,@OperateDate,@CategoryName");
            strSql.Append(") ");

            SqlParameter[] parameters = {
			            new SqlParameter("@Id", SqlDbType.Int,4) ,            
                        new SqlParameter("@HotelId", SqlDbType.Int,4) ,            
                        new SqlParameter("@RoleName", SqlDbType.NVarChar,50) ,            
                        new SqlParameter("@roleid", SqlDbType.Int,4) ,            
                        new SqlParameter("@DineTable", SqlDbType.Int,4) ,            
                        new SqlParameter("@Dinecondition", SqlDbType.NVarChar,50) ,            
                        new SqlParameter("@DineTableName", SqlDbType.NVarChar,50) ,            
                        new SqlParameter("@OrderId", SqlDbType.Int,4) ,            
                        new SqlParameter("@HCId", SqlDbType.Int,4) ,            
                        new SqlParameter("@cName", SqlDbType.NVarChar,50) ,            
                        new SqlParameter("@Num", SqlDbType.Int,4) ,            
                        new SqlParameter("@Price", SqlDbType.Decimal,5) ,            
                        new SqlParameter("@State", SqlDbType.Int,4) ,            
                        new SqlParameter("@OperateDate", SqlDbType.DateTime) ,            
                        new SqlParameter("@CategoryName", SqlDbType.NVarChar,50)             
              
            };

            parameters[0].Value = model.Id;
            parameters[1].Value = model.HotelId;
            parameters[2].Value = model.RoleName;
            parameters[3].Value = model.roleid;
            parameters[4].Value = model.DineTable;
            parameters[5].Value = model.Dinecondition;
            parameters[6].Value = model.DineTableName;
            parameters[7].Value = model.OrderId;
            parameters[8].Value = model.HCId;
            parameters[9].Value = model.cName;
            parameters[10].Value = model.Num;
            parameters[11].Value = model.Price;
            parameters[12].Value = model.State;
            parameters[13].Value = model.OperateDate;
            parameters[14].Value = model.CategoryName;
            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

        }


        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(RBS.Core.Model.V_OrderDept model)
        {
            var strSql = new StringBuilder();
            strSql.Append("update V_OrderDept set ");

            strSql.Append(" Id = @Id , ");
            strSql.Append(" HotelId = @HotelId , ");
            strSql.Append(" RoleName = @RoleName , ");
            strSql.Append(" roleid = @roleid , ");
            strSql.Append(" DineTable = @DineTable , ");
            strSql.Append(" Dinecondition = @Dinecondition , ");
            strSql.Append(" DineTableName = @DineTableName , ");
            strSql.Append(" OrderId = @OrderId , ");
            strSql.Append(" HCId = @HCId , ");
            strSql.Append(" cName = @cName , ");
            strSql.Append(" Num = @Num , ");
            strSql.Append(" Price = @Price , ");
            strSql.Append(" State = @State , ");
            strSql.Append(" OperateDate = @OperateDate , ");
            strSql.Append(" CategoryName = @CategoryName  ");
            strSql.Append(" where Id=@Id and OrderId=@OrderId and HCId=@HCId and cName=@cName and Num=@Num and Price=@Price and State=@State and OperateDate=@OperateDate and CategoryName=@CategoryName and HotelId=@HotelId and RoleName=@RoleName and roleid=@roleid and DineTable=@DineTable and Dinecondition=@Dinecondition and DineTableName=@DineTableName  ");

            SqlParameter[] parameters = {
			            new SqlParameter("@Id", SqlDbType.Int,4) ,            
                        new SqlParameter("@HotelId", SqlDbType.Int,4) ,            
                        new SqlParameter("@RoleName", SqlDbType.NVarChar,50) ,            
                        new SqlParameter("@roleid", SqlDbType.Int,4) ,            
                        new SqlParameter("@DineTable", SqlDbType.Int,4) ,            
                        new SqlParameter("@Dinecondition", SqlDbType.NVarChar,50) ,            
                        new SqlParameter("@DineTableName", SqlDbType.NVarChar,50) ,            
                        new SqlParameter("@OrderId", SqlDbType.Int,4) ,            
                        new SqlParameter("@HCId", SqlDbType.Int,4) ,            
                        new SqlParameter("@cName", SqlDbType.NVarChar,50) ,            
                        new SqlParameter("@Num", SqlDbType.Int,4) ,            
                        new SqlParameter("@Price", SqlDbType.Decimal,5) ,            
                        new SqlParameter("@State", SqlDbType.Int,4) ,            
                        new SqlParameter("@OperateDate", SqlDbType.DateTime) ,            
                        new SqlParameter("@CategoryName", SqlDbType.NVarChar,50)             
              
            };

            parameters[0].Value = model.Id;
            parameters[1].Value = model.HotelId;
            parameters[2].Value = model.RoleName;
            parameters[3].Value = model.roleid;
            parameters[4].Value = model.DineTable;
            parameters[5].Value = model.Dinecondition;
            parameters[6].Value = model.DineTableName;
            parameters[7].Value = model.OrderId;
            parameters[8].Value = model.HCId;
            parameters[9].Value = model.cName;
            parameters[10].Value = model.Num;
            parameters[11].Value = model.Price;
            parameters[12].Value = model.State;
            parameters[13].Value = model.OperateDate;
            parameters[14].Value = model.CategoryName;
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int Id, int OrderId, int HCId, string cName, int Num, decimal Price, int State, DateTime OperateDate, string CategoryName, int HotelId, string RoleName, int roleid, int DineTable, string Dinecondition, string DineTableName)
        {

            var strSql = new StringBuilder();
            strSql.Append("delete from V_OrderDept ");
            strSql.Append(" where Id=@Id and OrderId=@OrderId and HCId=@HCId and cName=@cName and Num=@Num and Price=@Price and State=@State and OperateDate=@OperateDate and CategoryName=@CategoryName and HotelId=@HotelId and RoleName=@RoleName and roleid=@roleid and DineTable=@DineTable and Dinecondition=@Dinecondition and DineTableName=@DineTableName ");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4),
					new SqlParameter("@OrderId", SqlDbType.Int,4),
					new SqlParameter("@HCId", SqlDbType.Int,4),
					new SqlParameter("@cName", SqlDbType.NVarChar,50),
					new SqlParameter("@Num", SqlDbType.Int,4),
					new SqlParameter("@Price", SqlDbType.Decimal,5),
					new SqlParameter("@State", SqlDbType.Int,4),
					new SqlParameter("@OperateDate", SqlDbType.DateTime),
					new SqlParameter("@CategoryName", SqlDbType.NVarChar,50),
					new SqlParameter("@HotelId", SqlDbType.Int,4),
					new SqlParameter("@RoleName", SqlDbType.NVarChar,50),
					new SqlParameter("@roleid", SqlDbType.Int,4),
					new SqlParameter("@DineTable", SqlDbType.Int,4),
					new SqlParameter("@Dinecondition", SqlDbType.NVarChar,50),
					new SqlParameter("@DineTableName", SqlDbType.NVarChar,50)			};
            parameters[0].Value = Id;
            parameters[1].Value = OrderId;
            parameters[2].Value = HCId;
            parameters[3].Value = cName;
            parameters[4].Value = Num;
            parameters[5].Value = Price;
            parameters[6].Value = State;
            parameters[7].Value = OperateDate;
            parameters[8].Value = CategoryName;
            parameters[9].Value = HotelId;
            parameters[10].Value = RoleName;
            parameters[11].Value = roleid;
            parameters[12].Value = DineTable;
            parameters[13].Value = Dinecondition;
            parameters[14].Value = DineTableName;


            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }



        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public RBS.Core.Model.V_OrderDept GetModel(int Id, int OrderId, int HCId, string cName, int Num, decimal Price, int State, DateTime OperateDate, string CategoryName, int HotelId, string RoleName, int roleid, int DineTable, string Dinecondition, string DineTableName)
        {

            var strSql = new StringBuilder();
            strSql.Append("select Id, HotelId, RoleName, roleid, DineTable, Dinecondition, DineTableName, OrderId, HCId, cName, Num, Price, State, OperateDate, CategoryName  ");
            strSql.Append("  from V_OrderDept ");
            strSql.Append(" where Id=@Id and OrderId=@OrderId and HCId=@HCId and cName=@cName and Num=@Num and Price=@Price and State=@State and OperateDate=@OperateDate and CategoryName=@CategoryName and HotelId=@HotelId and RoleName=@RoleName and roleid=@roleid and DineTable=@DineTable and Dinecondition=@Dinecondition and DineTableName=@DineTableName ");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4),
					new SqlParameter("@OrderId", SqlDbType.Int,4),
					new SqlParameter("@HCId", SqlDbType.Int,4),
					new SqlParameter("@cName", SqlDbType.NVarChar,50),
					new SqlParameter("@Num", SqlDbType.Int,4),
					new SqlParameter("@Price", SqlDbType.Decimal,5),
					new SqlParameter("@State", SqlDbType.Int,4),
					new SqlParameter("@OperateDate", SqlDbType.DateTime),
					new SqlParameter("@CategoryName", SqlDbType.NVarChar,50),
					new SqlParameter("@HotelId", SqlDbType.Int,4),
					new SqlParameter("@RoleName", SqlDbType.NVarChar,50),
					new SqlParameter("@roleid", SqlDbType.Int,4),
					new SqlParameter("@DineTable", SqlDbType.Int,4),
					new SqlParameter("@Dinecondition", SqlDbType.NVarChar,50),
					new SqlParameter("@DineTableName", SqlDbType.NVarChar,50)			};
            parameters[0].Value = Id;
            parameters[1].Value = OrderId;
            parameters[2].Value = HCId;
            parameters[3].Value = cName;
            parameters[4].Value = Num;
            parameters[5].Value = Price;
            parameters[6].Value = State;
            parameters[7].Value = OperateDate;
            parameters[8].Value = CategoryName;
            parameters[9].Value = HotelId;
            parameters[10].Value = RoleName;
            parameters[11].Value = roleid;
            parameters[12].Value = DineTable;
            parameters[13].Value = Dinecondition;
            parameters[14].Value = DineTableName;


            RBS.Core.Model.V_OrderDept model = new RBS.Core.Model.V_OrderDept();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Id"].ToString() != "")
                {
                    model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["HotelId"].ToString() != "")
                {
                    model.HotelId = int.Parse(ds.Tables[0].Rows[0]["HotelId"].ToString());
                }
                model.RoleName = ds.Tables[0].Rows[0]["RoleName"].ToString();
                if (ds.Tables[0].Rows[0]["roleid"].ToString() != "")
                {
                    model.roleid = int.Parse(ds.Tables[0].Rows[0]["roleid"].ToString());
                }
                if (ds.Tables[0].Rows[0]["DineTable"].ToString() != "")
                {
                    model.DineTable = int.Parse(ds.Tables[0].Rows[0]["DineTable"].ToString());
                }
                model.Dinecondition = ds.Tables[0].Rows[0]["Dinecondition"].ToString();
                model.DineTableName = ds.Tables[0].Rows[0]["DineTableName"].ToString();
                if (ds.Tables[0].Rows[0]["OrderId"].ToString() != "")
                {
                    model.OrderId = int.Parse(ds.Tables[0].Rows[0]["OrderId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["HCId"].ToString() != "")
                {
                    model.HCId = int.Parse(ds.Tables[0].Rows[0]["HCId"].ToString());
                }
                model.cName = ds.Tables[0].Rows[0]["cName"].ToString();
                if (ds.Tables[0].Rows[0]["Num"].ToString() != "")
                {
                    model.Num = int.Parse(ds.Tables[0].Rows[0]["Num"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Price"].ToString() != "")
                {
                    model.Price = decimal.Parse(ds.Tables[0].Rows[0]["Price"].ToString());
                }
                if (ds.Tables[0].Rows[0]["State"].ToString() != "")
                {
                    model.State = int.Parse(ds.Tables[0].Rows[0]["State"].ToString());
                }
                if (ds.Tables[0].Rows[0]["OperateDate"].ToString() != "")
                {
                    model.OperateDate = DateTime.Parse(ds.Tables[0].Rows[0]["OperateDate"].ToString());
                }
                model.CategoryName = ds.Tables[0].Rows[0]["CategoryName"].ToString();

                return model;
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            var strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM V_OrderDept ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            var strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" * ");
            strSql.Append(" FROM V_OrderDept ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }


        #region  ExtensionMethod
        /// <summary>
        /// 获得查询分页数据
        /// </summary>
        public DataSet GetList(int pageSize, int pageIndex, string strWhere, string filedOrder, out int recordCount)
        {
            var strSql = new StringBuilder();
            strSql.Append("select * FROM V_OrderDept ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where 1=1 " + strWhere);
            }
            recordCount = Convert.ToInt32(DbHelperSQL.GetSingle(PagingHelper.CreateCountingSql(strSql.ToString())));
            return DbHelperSQL.Query(PagingHelper.CreatePagingSql(recordCount, pageSize, pageIndex, strSql.ToString(), filedOrder));
        }
        #endregion  ExtensionMethod


    }
}

